package noteServe

import (
	"forum/app/model/noteModel"
	"time"
)

type NoteResult struct {
	Id          int      `json:"id"`
	UserId      int      `json:"user_id"`
	Title       string   `json:"title"`
	Content     string   `json:"content"`
	CreatedTime int      `json:"created_time"`
	UpdatedTime int      `json:"updated_time"`
	Status      int      `json:"status"`
	ImgArr      []string `json:"img_arr"`
}

// GetNoteList 获取笔记列表
func GetNoteList(params map[string]interface{}) [][]interface{} {
	paramsData := []string{"title", "page", "limit"}
	for _, value := range paramsData {
		if paramValue, exists := params[value]; exists {
			if strValue, ok := paramValue.(string); ok && strValue == "" {
				delete(params, value)
			}
		}
	}
	return noteModel.GetNoteList(params)
}

// GetNoteDetail 获取笔记详情
func (result *NoteResult) GetNoteDetail() {
	//TODO...
}

// NoteCreate 创建帖子
func NoteCreate(data map[string]interface{}) int64 {
	if data["title"] == "" {
		panic("标题不能为空")
	}
	if data["content"] == "" {
		panic("内容不能为空")
	}
	noteData := map[string]interface{}{
		"user_id":      data["user_id"],
		"title":        data["title"],
		"content":      data["content"],
		"img_arr":      data["img_arr"],
		"status":       0,
		"created_time": time.Now().Unix(),
		"updated_time": time.Now().Unix(),
		"is_del":       0,
	}
	id := noteModel.NoteCreate(noteData)
	return id
}
